function foo(a, b, c, d, e){
    console.log(this);
    console.log(a, b, c, d, e);
}

var a = 0;
var obj = {
    a: 2,
    foo: foo
}

foo(1, 2, 3, 4, 5);
obj.foo(1, 2, 3, 4, 5)
// bind call apply 强制指定this指向
foo.bind(obj)(1, 2, 3, 4, 5);
foo.call(obj, 1, 2, 3, 4, 5);
foo.apply(obj, [1, 2, 3, 4, 5]);

// undefind 不是对象，默认绑定window
foo.call(obj, 1, 2, 3, 4, 5);
foo.apply(obj, [1, 2, 3, 4, 5]);


var initParam = (function(){
    var a = 1;
    var foo = {
        c: 3,
        a: 8,
        d: function(){
            console.log(this.a);
        }
    }
    var obj = {
        a: 2,
        b: function(){
            console.log(this.c);
        },
        d: foo.d
    }

    obj.b.call(foo);
    obj.d.call(foo);
})();

var initConstructor = (function(){
    function Super(){
        this.a = 1;
        this.b = function(){
            console.log(this.a);
        }
    }

    Super.prototype.name = 'jack';

    function Sub(){
        Super.call(this);
        this.c = 2;
        this.d = function(){
            console.log(this.a);
        }
    }

    // Sub.prototype = new Super();

    var sub = new Sub();

    console.log(sub, 'sub');

})();

function init(){
    initParam,
    initConstructor
}

window.onload = function(){
    init();
}